local skel = fk.CreateSkill {
  name = "efengqi__guqu",
}

Fk:loadTranslationTable{
  ["efengqi__guqu"] = "顾曲",
  [":efengqi__guqu"] = "出牌阶段限一次，你可以展示一名其他角色的手牌并选一项：1.弃置其一种花色所有牌；2.交给其缺少花色各一张牌；你或其以此法失去牌后，可令对方失去一点体力。",

  ["#efengqi__guqu"] = "顾曲：展示一名其他角色的手牌，选择弃置其中牌，或交给其牌令其失去体力",
  ["#efengqi__guqu-throw"] = "顾曲：弃置其一种花色所有牌",
  ["#efengqi__guqu-losehp"] = "顾曲：选确定让 %src 失去1点体力",
  ["efengqi__guqu_active"] = "顾曲",
  ["#efengqi__guqu-give"] = "顾曲：你须交给 %src %arg 花色各一张牌",

  ["$efengqi__guqu1"] = "曲有误，不可不顾。",
  ["$efengqi__guqu2"] = "兀音曳绕梁，愿君去芜存菁。",
}
local U = require "packages/utility/utility"

skel:addEffect("active", {
  anim_type = "offensive",
  prompt = "#efengqi__guqu",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to, selected)
    return #selected == 0 and player ~= to and not to:isKongcheng()
  end,
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    to:showCards(to:getCardIds("h"))
    if player.dead or to.dead then return end
    room:delay(600)
    local suitMap = {}
    for _, id in ipairs(to:getCardIds("he")) do
      local suit = Fk:getCardById(id):getSuitString(true)
      if suitMap[suit] == nil then
        suitMap[suit] = {id}
      else
        table.insert(suitMap[suit], id)
      end
    end
    local suits, cardList = {}, {}
    for suit, ids in pairs(suitMap) do
      table.insert(suits, suit)
      table.insert(cardList, ids)
    end
    local names = U.askForChooseCardList(room, player, suits, cardList, 1, 1, skel.name, "#efengqi__guqu-throw", false, true)
    if #names > 0 then
      room:throwCard(suitMap[names[1]], skel.name, to, player)
      if not to.dead and not player.dead then
        if room:askToSkillInvoke(to, { skill_name = skel.name, prompt = "#efengqi__guqu-losehp:"..player.id}) then
          room:loseHp(player, 1, skel.name)
        end
      end
    else
      local suitsToGive, give = {}, {}
      for _, id in ipairs(player:getCardIds("he")) do
        local suit = Fk:getCardById(id):getSuitString(true)
        if not table.contains(suits, suit) then
          if table.insertIfNeed(suitsToGive, suit) then
            table.insert(give, id)
          end
        end
      end
      if #suitsToGive == 0 or #suitsToGive < (4 - #suits) then return end
      local str = table.concat(table.map(suitsToGive, function (s) return Fk:translate(s) end), ", ")
      local _, dat = room:askToUseActiveSkill(player, {
        skill_name = "efengqi__guqu_active", prompt = "#efengqi__guqu-give:"..to.id.."::"..str,
        cancelable = false, extra_data = {suits = suitsToGive}
      })
      if dat then
        give = dat.cards
      end
      room:obtainCard(to, give, true, fk.ReasonGive, player, skel.name)
      if not to.dead and not player.dead then
        if room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#efengqi__guqu-losehp:"..to.id}) then
          room:loseHp(to, 1, skel.name)
        end
      end
    end
  end,
})



return skel
